<?php
/**
 * 用户中心
 *
 */
class passport
{
    private $_error = 0;

    /**
     * 注册新用户
     */
    public function register($data) {
    	$user_mod = D('user');
       if (false !== $user_mod->create($data)) {
            $uid = $user_mod->add();
            if (!$uid) {
                $this->_error = $user_mod->getError();
                return false;
            } else {
                return $uid;
            }
        } else {
            $this->_error = $user_mod->getError();
            return false;
        }
    }

    /**
     * 修改用户资料
     */
    public function edit($uid, $old_password, $data) {
        if(!M('user')->where(array('id'=>$uid,'password'=> md5($old_password)))->count()){
        	    $this->_error = '旧密码不正确';
                return false;
         }
        //本地修改
         M('user')->where(array('id'=>$uid))->save($data);
        return true;
    }



    /**
     * 登陆验证
     */
    public function auth($username, $password) {
       $map['password'] = md5($password);
       $map['mobile']=$username;
       $map['status']=1;
       $user= M('user')->where($map)->field('id')->find();
       $uid=$user['id'];
        if ($uid) {
            return $uid;
        } else {
            $this->_error ='您输入的账户或密码错误，请核对后重新输入';
            return false;
        }
    }

    public function get_error() {
        return $this->_error;
    }
}